using FineCollection.Const;
using FineCollection.Test;

using NUnit.Framework;



namespace FineCollection.Cont
{
    [TestFixture]
    public class ArrList_test
    {

        [Test]
        public void Test_Basic0()
        {
            var list = new ArrList<long>(1);

            list.Count       ._equals_(0);
            list.IsEmpty     ._true_();
            list.IsNotEmpty  ._false_();
        }


        [Test]
        public void Test_Basic1()
        {
            var list = new ArrList<long>(1);

            list.Add(777L);

            list.Count       ._equals_(1);
            list.IsEmpty     ._false_();
            list.IsNotEmpty  ._true_();
        }


        [Test]
        public void Test_Basic3()
        {
            var list = new ArrList<long>(1, 3);

            list.Add(1111L);
            list.Add(2222L);
            list.Add(3333L);

            list.Count  ._equals_(3);
            list[1]     ._equals_(1111L);
            list[2]     ._equals_(2222L);
            list[3]     ._equals_(3333L);
        }


        [Test]
        public void Test_Floats()
        {
            var list = new ArrList<float>(1, 3);

            list.Add(1.0f);
            list.Add(2.718281828f);
            list.Add(3.14159265f);

            list[1]     ._equals_(1.0f);
            list[2]     ._equals_(2.718281828f);
            list[3]     ._equals_(3.14159265f);
        }


        [Test]
        public void test_Iterator_Where()
        {
            ArrList<long> list = new ArrList<long>(1,10) {1111, 2222, 3333};
            var it = list.TakeIterator();

            Assert.That(it.Where, Is.EqualTo(-1));
            it.Next(); // 1111
            Assert.That(it.Where, Is.EqualTo(0));
            it.Next(); // 2222
            Assert.That(it.Where, Is.EqualTo(0));
            it.Next(); // 3333
            Assert.That(it.Where, Is.EqualTo(0));
            it.Next(); // behind the end
            Assert.That(it.Where, Is.EqualTo(+1));
        }
        

        [Test]
        public void test_IteratorToTheEnd()
        {
            ArrList<long> list = new ArrList<long>(1,10) {3333, 4444};
            var it = list.TakeIterator();

            it.Next();
            Assert.That(it.Current, Is.EqualTo(3333));
            it.Next();
            Assert.That(it.Current, Is.EqualTo(4444));
            it.Next();
        }


        [Test]
        public void test_AddAllFromArrayList()
        {
            var list = new ArrList<ulong>(1, 6);
            list.Add(1111);
            list.Add(2222);
            list.Add(3333);
            list.Add(4444);

            var src = new ArrList<ulong>(1, 7);
            src.Add(5555);
            src.Add(6666);
            src.Add(7777);
            src.Add(8888);

            list.AddAll(src);
            
            Assert.That(list.Count, Is.EqualTo(8));
            Assert.That(list[1], Is.EqualTo(1111));
            Assert.That(list[2], Is.EqualTo(2222));
            Assert.That(list[3], Is.EqualTo(3333));
            Assert.That(list[4], Is.EqualTo(4444));
            Assert.That(list[5], Is.EqualTo(5555));
            Assert.That(list[6], Is.EqualTo(6666));
            Assert.That(list[7], Is.EqualTo(7777));
            Assert.That(list[8], Is.EqualTo(8888));
        }


        [Test]
        public void test_AddAllFromConstList()
        {
            var list = new ArrList<ulong>(1, 6);
            list.Add(1111);
            list.Add(2222);
            list.Add(3333);
            list.Add(4444);

            var src = CC1.ListOf(5555uL, 6666uL, 7777uL, 8888uL);

            list.AddAll(src);
            
            Assert.That(list.Count, Is.EqualTo(8));
            Assert.That(list[1], Is.EqualTo(1111));
            Assert.That(list[2], Is.EqualTo(2222));
            Assert.That(list[3], Is.EqualTo(3333));
            Assert.That(list[4], Is.EqualTo(4444));
            Assert.That(list[5], Is.EqualTo(5555));
            Assert.That(list[6], Is.EqualTo(6666));
            Assert.That(list[7], Is.EqualTo(7777));
            Assert.That(list[8], Is.EqualTo(8888));
        }


        [Test]
        public void test_AddAllFromCollection()
        {
            var list = new ArrList<ulong>(1, 6);
            list.Add(1111);
            list.Add(2222);
            list.Add(3333);
            list.Add(4444);

            var src = new LinkList<ulong>();
            src.Add(5555);
            src.Add(6666);
            src.Add(7777);
            src.Add(8888);

            list.AddAll(src);

            Assert.That(list.Count, Is.EqualTo(8));
            Assert.That(list[1], Is.EqualTo(1111));
            Assert.That(list[2], Is.EqualTo(2222));
            Assert.That(list[3], Is.EqualTo(3333));
            Assert.That(list[4], Is.EqualTo(4444));
            Assert.That(list[5], Is.EqualTo(5555));
            Assert.That(list[6], Is.EqualTo(6666));
            Assert.That(list[7], Is.EqualTo(7777));
            Assert.That(list[8], Is.EqualTo(8888));
        }


        /*
        [Test]
        public void test_AddAllFromMicrosoftList()
        {
            var list = new ArrList<ulong>(1, 6);
            list.Add(1111);
            list.Add(2222);
            list.Add(3333);
            list.Add(4444);

            var src = new System.Collections.Generic.List<long>();
            src.Add(5555);
            src.Add(6666);
            src.Add(7777);
            src.Add(8888);

            list.AddAll(src);
            
            Assert.That(list.Count, Is.EqualTo(8));
            Assert.That(list[1], Is.EqualTo(1111));
            Assert.That(list[2], Is.EqualTo(2222));
            Assert.That(list[3], Is.EqualTo(3333));
            Assert.That(list[4], Is.EqualTo(4444));
            Assert.That(list[5], Is.EqualTo(5555));
            Assert.That(list[6], Is.EqualTo(6666));
            Assert.That(list[7], Is.EqualTo(7777));
            Assert.That(list[8], Is.EqualTo(8888));
        }
        */



    }
}